package com.ymatou.iapi.exp.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.exp.parameter.GetOverstepUserCountBean;
import com.ymatou.iapi.exp.service.GetOverstepUserCountCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ExpCallService;
import com.ymttest.database.sqlwapper.ExpWapper;
/**
*获取当前用户的经验值超出了多少个用户
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetOverstepUserCount{
	private static GetOverstepUserCountBean getoverstepusercountBean;
	private static GetOverstepUserCountCall getoverstepusercountCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取当前用户的经验值超出了多少个用户");
	}

	@Before
	public void caseUp() {
		getoverstepusercountBean=new GetOverstepUserCountBean();
		getoverstepusercountCall=new GetOverstepUserCountCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getoverstepusercountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetOverstepUserCount_001() {
		Logger.start(true,"获取当前用户的经验值超出了多少个用户成功");
		try {
			ExpWapper ew = new ExpWapper();
			int exp=1050;
			ExpCallService.resetExp(1, exp);
			getoverstepusercountBean.setUserId(1);
			getoverstepusercountCall.setData(getoverstepusercountBean);
			getoverstepusercountCall.callService();			
			Logger.verifyEquals("success", getoverstepusercountCall.getErrorMessage(), "验证errormessage");
			Logger.verifyEquals("true", getoverstepusercountCall.getSuccess(), "验证success");
			Logger.verifyEquals("0", getoverstepusercountCall.getErrorCode(), "验证ErrorCode");
			Double re=ew.selectuserexp(1).get(0).getPercents();
//			long max=ew.selectLtExp(Integer.MAX_VALUE);
//			long now=ew.selectLtExp(exp);
			//经验值占全用户百分比走缓存 1天跑一次数据
			if(re!=0&&re!=1){
				Logger.verifyEquals(re*100, Double.valueOf(getoverstepusercountCall.getString("result")), "验证result");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetOverstepUserCount_002() {
		Logger.start(true,"不输入uid失败");
		try {
			getoverstepusercountCall.setData(getoverstepusercountBean);
			getoverstepusercountCall.callService();			
			Logger.verifyEquals("success", getoverstepusercountCall.getErrorMessage(), "验证errormessage");
			Logger.verifyEquals("true", getoverstepusercountCall.getSuccess(), "验证success");
			Logger.verifyEquals("0", getoverstepusercountCall.getErrorCode(), "验证ErrorCode");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}